<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
	xmlns:m3="http://www.openM3.org/m3"
    xmlns:eko="http://www.ia.pw.edu.pl/m3/eko">
    
    <xsl:import href="toampl-utilities.xsl"/>
    
	<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
	
	    <xsl:param name="_admitance">op:arcReactance</xsl:param>
    <xsl:param name="_PTDF">op:PTDF</xsl:param>
    <xsl:param name="_PTDFValuesForSource">op:PTDFValuesForSource</xsl:param>
    <xsl:param name="_ValueofPTDF">op:ValueofPTDF</xsl:param>
    <xsl:param name="_singlePTDFValue">op:singlePTDFValue</xsl:param>
    <xsl:param name="_sourceNode">op:sourceNode</xsl:param>
	<xsl:param name="_sinkNode">op:sinkNode</xsl:param>
	<xsl:param name="_Node">(op:OverheadLine|op:Pole|op:PointOfConnection)</xsl:param>
	<xsl:param name="_Line">(op:FuseLine|op:LVNetworkLine|op:ConnectionCable)</xsl:param>
	<xsl:param name="_arcCapacity">op:arcLongTermRating</xsl:param>
	<xsl:param name="_arcActivePowerCapacity">op:arcActivePowerLongTermRating</xsl:param>

	
	<xsl:template match="/data">

		# generated by file: toAmpl-GENERIC-withTime.xsl<xsl:call-template name="newline"/>
		# available at page: http://www.openm3.org/content/view/19/29/<xsl:call-template name="newline"/>
		set OFFERS;
		set COMMODITIES;
		
		param share{p in OFFERS, c in COMMODITIES};
		param price{p in OFFERS};
		param offer_lower_bound{p in OFFERS};
		param offer_upper_bound{p in OFFERS};
		
		var offer{p in OFFERS} >= 0, integer;
		
		maximize welfare: sum{p in OFFERS} offer[p]*price[p];
		
		subject to min_balance_c{c in COMMODITIES} : sum {p in OFFERS} offer[p] * share[p,c] &gt;= 0;
		subject to max_balance_c{c in COMMODITIES} : sum {p in OFFERS} offer[p] * share[p,c] &lt;= 0;
		subject to constr_lower{p in OFFERS}       : offer[p] &gt;= offer_lower_bound[p];
		subject to constr_upper{p in OFFERS}       : offer[p] &lt;= offer_upper_bound[p];
		
		
		data;
		set OFFERS := <xsl:for-each select="m3:offers/m3:Offer">
			<xsl:apply-templates select="." mode="set"/>
			<xsl:text> </xsl:text></xsl:for-each>;
			
		set COMMODITIES := <xsl:for-each select="m3:commodities/m3:Commodity">
			<xsl:if test="boolean(m3:VirtualCommodity) = false()">
				<xsl:apply-templates select="." mode="set"/>
				<xsl:text> </xsl:text>
			</xsl:if></xsl:for-each>;


		<xsl:call-template name="parameters"/>
		end;
	</xsl:template>
	
	<xsl:template name="parameters">


		<xsl:call-template name="generic_parameters">	
			<xsl:with-param name="dimension">2</xsl:with-param>
			<xsl:with-param name="param_name">share</xsl:with-param>
			<xsl:with-param name="param_template">share_param</xsl:with-param>
		</xsl:call-template>
	
		<xsl:call-template name="generic_parameters">	
			<xsl:with-param name="dimension">1</xsl:with-param>
			<xsl:with-param name="param_name">price</xsl:with-param>
			<xsl:with-param name="param_xpath">offeredPrice</xsl:with-param>
			<xsl:with-param name="param_set">m3:Offer</xsl:with-param>
		</xsl:call-template>
	
		<xsl:call-template name="generic_parameters">	
			<xsl:with-param name="dimension">1</xsl:with-param>
			<xsl:with-param name="param_name">offer_lower_bound</xsl:with-param>
			<xsl:with-param name="param_xpath">minValue</xsl:with-param>
			<xsl:with-param name="param_set">m3:Offer</xsl:with-param>
		</xsl:call-template>
	
		<xsl:call-template name="generic_parameters">	
			<xsl:with-param name="dimension">1</xsl:with-param>
			<xsl:with-param name="param_name">offer_upper_bound</xsl:with-param>
			<xsl:with-param name="param_xpath">maxValue</xsl:with-param>
			<xsl:with-param name="param_set">m3:Offer</xsl:with-param>
		</xsl:call-template>
	
	</xsl:template>


</xsl:stylesheet>
